/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worlds.ui.edge;

import java.awt.Color;
import java.awt.Graphics2D;
import net.worlds.WorldsException;
import net.worlds.LocalPlayer;
import net.worlds.Main;

/**
 *
 * @author Jacob
 */
public class EHealthFrame extends EFrame{
    protected final Color defaultToolColor = new Color(100, 100, 100, 200);
    protected final Color selectedToolColor = new Color(170, 170, 185, 255);
    protected final Color healthColor = new Color(10, 170, 40);
    public EHealthFrame(int x, int y)
    {
        super(x, y, 100, 100);
    }
    public void render(Graphics2D g)
    {
        if(Main.getLocalPlayer() != null)
        {
            LocalPlayer player = Main.getLocalPlayer();
            g.setColor(defaultToolColor);
            g.fillRect(2, 2, 100, 20);
            try {
                if(player.getPlayer().getProp("Character") != null && player.getPlayer().getProp("Character") instanceof net.worlds.object.Character)
                {
                    int health = player.getPlayer().getObjectProp("Character").getIntProp("Health");
                    int maxHealth = player.getPlayer().getObjectProp("Character").getIntProp("MaximumHealth");
                    if(maxHealth != 0)
                    {
                        g.setColor(healthColor);
                        double percent = (double) health/maxHealth;
                        int barWidth = (int) (100 * percent);
                        g.fillRect(2, 2, barWidth, 20);
                    }
                }
            g.setColor(selectedToolColor);
            g.drawRect(2, 2, 100, 18);
            } catch (WorldsException ex) {
                ex.printStackTrace();
            }
        }
    }
}
